package com.chixing.day16.day16_H;


import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class ProductTest {
    public static void main(String[] args) {
        boolean result1 = hashGetMethod(Product.class,"proId");
        boolean result2 = hashSetMethod(Product.class,"proId");
        System.out.println(result1);
        System.out.println(result2);
    }
    public static boolean hashGetMethod(Class<?> clazz, String filedName) {
        Field field = null;
        try {
            field  = clazz.getDeclaredField(filedName); //获取本类中的属性成员
            System.out.println(field.getType().getName() );
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
       Method[] methods = clazz.getDeclaredMethods();
        for(Method method : methods) {
            if (method.getName().equals("getProId")  && method.getReturnType().getName().equals("int")
                 && method.getParameterCount() == 0){
                return true;
            }
        }
        return false;
    }

    public static boolean hashSetMethod(Class<?> clazz, String filedName){
        Field field = null;
        try {
            field  = clazz.getDeclaredField(filedName);
            System.out.println(field.getType());
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
        Method[] methods =clazz.getDeclaredMethods();
        for(Method method : methods){
            Class<?>[] param = method.getParameterTypes();
            for (Class<?> aClass : param) {
                if (method.getName().equals("setProId") && method.getReturnType().getName().equals("void")
                        && aClass.getName().equals("int")){
                    return true;
                }
            }
        }
        return false;
    }
}
